package net.lahuobao.export.service.impl;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.lahuobao.export.datasoruce.annotation.ExportField;
import net.lahuobao.export.datasoruce.dao.ExportMapper;
import net.lahuobao.export.service.tranf.IDicTranf;
/**
 * 字典表翻译工具类
 * @author Administrator
 *
 */
@Service("dicTranfService")
public class DicTranfImpl implements IDicTranf {
	@Autowired
	private ExportMapper exportDao;
	@Override
	public Object dicTranf(Object o ,Field field) {
	    Object d =null;
		try {
			PropertyDescriptor propDesc = new PropertyDescriptor(field.getName(),o.getClass());
			Method methodGet=propDesc.getReadMethod();
			try {
				d = methodGet.invoke(o);
				if(null!=d && !d.equals("")){
					Map map = new HashMap();
					map.put("key", d);
					map.put("dicType", field.getAnnotation(ExportField.class).dictType());
					Map resultMap=exportDao.queryInfoByDic(map);
					if(null!=resultMap){
						d= resultMap.get("codevalue");
					}
				}
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return d;
	}

}
